package com.codeti.core.wordcount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author: zhenzhong.wang@honeywell.com
 * @date: 2019/10/8 2:49 PM
 */
public class WordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
  @Override
  protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
    int total = 0;

    // values是一个集合
    for (LongWritable value : values) {
      total += value.get();
    }

    context.write(key, new LongWritable(total));
  }
}
